#include <iostream>
#include <opencv2/opencv.hpp>
#include "orin_detect.h"
#include "detector.h"
#include "common_structs.h"

using namespace std;
using namespace cv;

int main()
{
    Appconfig config;
    string json_path = "../../settings.json";
    load_config(config, json_path);
    Nv_Detector nv_detector;
    Appconfig* ptr = &config;
    nv_detector.Init(ptr);
    
    Mat img0 = imread("../538.png");
    Mat img1 = imread("../533.jpg");
    Mat pr_img;
    // resize(img0, img0, Size(1920,1080));
    nv_detector.input_img_ = img1;
    nv_detector.input_img2_ = img1;
    nv_detector.Nv_Init();
    auto start = std::chrono::high_resolution_clock::now();
    auto end = std::chrono::high_resolution_clock::now();
    float elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
    int fps;
    while (1)
    {   
        
        end =  std::chrono::high_resolution_clock::now();
        elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
        fps++;
        //cout << elapsed << endl;
        if (elapsed/1000 > 1000)
        {
            cout << fps << endl;
            start = end;
            fps = 0;
        }
        
        nv_detector.detect();
        //cout << elapsed/1000 << endl;
        //nv_detector.show_results(nv_detector.input_img_, nv_detector.outputs_);
        //nv_detector.show_results(nv_detector.input_img2_, nv_detector.outputs2_);
        //imshow("1",nv_detector.input_img_);
        //cv::imwrite("out.jpg", nv_detector.input_img_);
        //imshow("2",nv_detector.input_img2_);
        //waitKey(0);
        //exit(0);
    }

    return 0;
}